//-------------------------------------------------------------------
//	Copyright (c) 2010-2011  Zhirnov Andrey
//	This file is part of the "UXGEN_ResourceConverter" project.
//	See copyright notice in "Converter.h".
//-------------------------------------------------------------------

#ifndef _RC_STDAFX_H
#define _RC_STDAFX_H


#include <Includes.h>
#include "..\\..\\..\\Engine\\Systems\\FileSys\\IFile.h"
#include "..\\..\\..\\Engine\\Systems\\FileSys\\CFile.h"


#include "..\\..\\..\\Engine\\Resources\\Textures\\Image.h"
#include "..\\..\\..\\Engine\\Resources\\Models\\Geometry.h"
#include "..\\..\\..\\Engine\\Resources\\Sounds\\SoundSource.h"
#include "..\\..\\..\\Engine\\Resources\\Loaders\\AllLoaders.h"


inline E_COLOR_CHANNEL GetChannel(GLenum channel)
{
	switch ( channel )
	{
		case GL_ZERO	:	return CC_GL_ZERO;
		case GL_ONE		:	return CC_GL_ONE;
		case GL_RED		:	return CC_GL_RED;
		case GL_BLUE	:	return CC_GL_BLUE;
		case GL_GREEN	:	return CC_GL_GREEN;
		case GL_ALPHA	:	return CC_GL_ALPHA;
		default			:	return CC_GL_ONE;
	};
}


inline GLenum GetGLChannel(E_COLOR_CHANNEL channel)
{
	switch ( channel )
	{
		case CC_GL_ZERO	:	return GL_ZERO;
		case CC_GL_ONE	:	return GL_ONE;
		case CC_GL_RED	:	return GL_RED;
		case CC_GL_BLUE	:	return GL_BLUE;
		case CC_GL_GREEN:	return GL_GREEN;
		case CC_GL_ALPHA:	return GL_ALPHA;
		default			:	return GL_ONE;
	};
}


#ifdef __EC_DEBUG__
#	undef  _DEBUG
#	define _DEBUG
#endif

#ifdef PLATFORM_WINDOWS
#	define _MESSAGE( _text, _file, _line ) \
		{ \
			int	__ret = ::MessageBoxA( NULL, (string(_text)<<"\nfile: "<<_file<<"\nline: "<<_line).cstr(), \
									   "Assert message", MB_ABORTRETRYIGNORE | MB_ICONERROR | MB_SETFOREGROUND ); \
			switch ( __ret ) { \
				case IDABORT	:	exit(0);		break; \
				case IDRETRY	:	BREAK_POINT();	break; \
			}; \
		}
#endif

#undef  ASSERT
#undef  ASSERT_EXT

#define ASSERT( _b_val )					if ( !(_b_val) ) _MESSAGE( #_b_val, __FILE__, __LINE__ );
#define ASSERT_EXT( _b_val, _p_msg )		if ( !(_b_val) ) _MESSAGE( _p_msg, __FILE__, __LINE__ );



#define IBASE_IMPLEMENTATION(interface_name) \
	HRESULT CALLBACK GetGUID(GUID &guid) \
	{ \
		guid = IID_##interface_name; \
		return S_OK; \
	} \
	\
	HRESULT CALLBACK QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject) \
	{ \
		*ppvObject = nullptr;\
		if ( ::memcmp( &riid, &__uuidof(IUnknown), sizeof(GUID) ) == 0 ) \
			*ppvObject = static_cast< IUnknown *>(this); \
		else \
		if ( ::memcmp( &riid, &IID_##interface_name, sizeof(GUID) ) == 0 ) \
			*ppvObject = static_cast< interface_name *>(this); \
		else \
			return E_NOINTERFACE; \
		return S_OK; \
	} \
	ULONG CALLBACK AddRef()		{ return 1; } \
	ULONG CALLBACK Release()	{ return 1; }


#endif	// _RC_STDAFX_H